package leetcode.jianzhioffer;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-13 00:31
 **/
public class JianZhiOffer62 {

    public int lastRemaining(int n, int m) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(i);
        }
        //临时变量
        int temp = 0;
        while (list.size() > 1) {
            int len = list.size();
            temp = (temp + m - 1) % len;
            list.remove(temp);
        }
        return list.get(0);
    }

}
